package com.lianjing.sh.acceleo.controller.mvc.controller.module;

import org.eclipse.uml2.uml.Class;

public class ModuleService {
	
	public Boolean isModule(org.eclipse.uml2.uml.Element obj){
		if(!(obj instanceof org.eclipse.uml2.uml.Class)){
			return false;
		}
		org.eclipse.uml2.uml.Class aClass = (Class) obj;
		return 
			isFunModule(aClass)
			|| isPageModule(aClass)
			|| isListModule(aClass)
			|| isTreeModule(aClass)
			|| isInfoModule(aClass)
			|| isAddModule(aClass)
			|| isEditModule(aClass);
	}
	
	public Boolean isFunModule(org.eclipse.uml2.uml.Class aClass){
		return isModuleType(aClass, "Fun");
	}
	public Boolean isPageModule(org.eclipse.uml2.uml.Class aClass){
		return isModuleType(aClass, "Page");
	}
	public Boolean isListModule(org.eclipse.uml2.uml.Class aClass){
		return isModuleType(aClass, "List");
	}
	public Boolean isTreeModule(org.eclipse.uml2.uml.Class aClass){
		return isModuleType(aClass, "Tree");
	}
	public Boolean isInfoModule(org.eclipse.uml2.uml.Class aClass){
		return isModuleType(aClass, "Info");
	}
	public Boolean isAddModule(org.eclipse.uml2.uml.Class aClass){
		return isModuleType(aClass, "Add");
	}
	public Boolean isEditModule(org.eclipse.uml2.uml.Class aClass){
		return isModuleType(aClass, "Edit");
	}
	
	/**
	 * 
	 */
	public Boolean isModuleHead(org.eclipse.uml2.uml.Class aClass){
		Boolean type = isModuleType(aClass, "Head");
		if(!type && isModule(aClass.getOwner())){
			return aClass.getName().trim().equals("Head");
		}
		return type;
	}
	public Boolean isModuleBody(org.eclipse.uml2.uml.Class aClass){
		Boolean type = isModuleType(aClass, "Body");
		if(!type && isModule(aClass.getOwner())){
			return aClass.getName().trim().equals("Body");
		}
		return type;
	}
	
	private Boolean isModuleType(org.eclipse.uml2.uml.Class aClass, String type){
		if(null == aClass.getAppliedStereotype("profile::web::module::Module_"+type)){
			return false;
		}else{
			return true;
		}
	}
	
}
